package com.example.day2.busi.my;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.day2.R;
import com.example.day2.adapter.StoreAdapter;
import com.example.day2.databinding.FragmentStoreBinding;
import com.example.day2.entity.VideoResult;
import com.example.day2.mvvm.base.BaseFragment;
import com.example.day2.mvvm.base.BaseViewFragment;
import com.example.day2.mvvm.utils.DBUtils;

import java.util.List;


public class StoreFragment extends BaseViewFragment<FragmentStoreBinding> {
    private StoreAdapter storeAdapter = new StoreAdapter(R.layout.item_store);
    @Override
    public void initView() {
        binding.rv.setLayoutManager(new GridLayoutManager(getContext(),2));
        binding.rv.setAdapter(storeAdapter);
    }

    @Override
    public void initData() {
        //查询数据库，获取收藏的视频
        List<VideoResult.DataBean> list = DBUtils.getInstance().getStoreVideoDap().getAll();
        storeAdapter.getData().addAll(list);
        storeAdapter.notifyDataSetChanged();

    }

    @Override
    public void onResume() {
        super.onResume();
        //查询数据库，获取收藏的视频
        storeAdapter.getData().clear();
        List<VideoResult.DataBean> list = DBUtils.getInstance().getStoreVideoDap().getAll();

        storeAdapter.getData().addAll(list);
        storeAdapter.notifyDataSetChanged();
    }

    @Override
    public int bindLayoutId() {
        return R.layout.fragment_store;
    }
}